package com.awspaas.user.apps.cpq.event;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListener;
import com.actionsoft.bpms.bpmn.engine.listener.ListenerConst;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.exception.BPMNError;

public class InstallationFeeFormBeforeSave extends InterruptListener{

	public InstallationFeeFormBeforeSave() {
		setDescription("安装费报价模板中，保存时校验启动中的数据中是否有和项目类型与产品型号和定制说明重复的数据。");
	}

	@Override
	public boolean execute(ProcessExecutionContext pec) throws Exception {
		try {
			String bindId=pec.getProcessInstance().getId();
			//BO表名
	        String boName = pec.getParameterOfString(ListenerConst.FORM_EVENT_PARAM_BONAME);
	        if(boName.equals("BO_EU_CQP_INSTALLATION_FEE_TEMPLATE")) {
	        	BO formData = (BO) pec.getParameter(ListenerConst.FORM_EVENT_PARAM_FORMDATA);
	        	String xmlx=formData.getString("XMLX");
	        	String cpxh=formData.getString("CPXH");
	        	String dzsm=formData.getString("DZSM");
	        	String sql="select  * from BO_EU_CQP_INSTALLATION_FEE_TEMPLATE where XMLX=? and CPXH=? and DZSM=? and STATUS='启用' and BINDID!='"+bindId+"'";
	        	RowMap map=DBSql.getMap(sql, new Object[] {xmlx,cpxh,dzsm});
	        	if(null!=map) {
	        		throw new BPMNError("003", "项目类型为:"+xmlx+",产品型号为:"+cpxh+",定制说明为:"+dzsm+"的模板数据,在安装费报价标准模板台账中已存在，请重新输入项目类型、产品型号、定制说明。");
	        	}
	        }
			return true;
		} catch (Exception e) {
			throw e;
		}
		
	}

}
